package com.lishe.lishe.lishe.ImageSelector;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by shino on 2017/10/19.
 */

public class FloderAdapter extends BaseAdapter {
    private List<ImageObject> images;
    private Context context;
    private ImageLoaderUtils imageLoaderUtils;
    private int index = -1;

    public FloderAdapter(Context context, List<ImageObject> images) {
        this.context = context;
        this.images = images;
        imageLoaderUtils = new ImageLoaderUtils();
    }

    @Override
    public int getCount() {
        return images == null ? 0 : images.size();
    }

    @Override
    public Object getItem(int i) {
        return images.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = View.inflate(context, R.layout.item_image_floder_selector, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.name.setText(images.get(i).getName());
        viewHolder.count.setText(images.get(i).getImageSize() + "张");
        if (images.get(i).isCheck()) {
            viewHolder.select_icon.setImageResource(R.mipmap.sel_choice_icon);
        } else {
            viewHolder.select_icon.setImageResource(R.mipmap.circle_white_icon);
        }
        imageLoaderUtils.displayLocationImage(images.get(i).getPath(), viewHolder.image);
//        viewHolder.item_layout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (index != -1) {
//                    images.get(index).setCheck(false);
//                }
//                index = i;
//                images.get(i).setCheck(!images.get(i).isCheck());
//                notifyDataSetChanged();
//            }
//        });
        return view;
    }

    public class ViewHolder {
        private RelativeLayout item_layout;
        private ImageView image;
        private ImageView select_icon;
        private TextView name;
        private TextView count;

        ViewHolder(View v) {
            item_layout = v.findViewById(R.id.item_layout);
            image = v.findViewById(R.id.img);
            select_icon = v.findViewById(R.id.select_icon);
            name = v.findViewById(R.id.name);
            count = v.findViewById(R.id.count);
        }
    }
}
